package com.gk.panda.apis.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gk.panda.apis.Vo.RealtimeShootListVo;
import com.gk.panda.apis.dto.BiologyPointSearchDto;
import com.gk.panda.apis.entity.TransectManager.vo.EquipmentPointVo;
import com.gk.panda.apis.entity.largeScreen.Enum.OrgEnum;
import com.gk.panda.apis.entity.largeScreen.dto.EPListDto;
import com.gk.panda.apis.entity.largeScreen.dto.PatrolInfoDto;
import com.gk.panda.apis.entity.largeScreen.dto.PatrolListDto;
import com.gk.panda.apis.entity.largeScreen.vo.*;
import com.gk.panda.apis.service.*;
import com.gk.panda.apis.util.QRCodeUtil;
import com.gk.panda.commons.result.Result;
import com.gk.panda.pojo.BiologyPoint;
import com.gk.panda.pojo.Org;
import com.gk.panda.pojo.RealtimeShoot;
import com.gk.panda.pojo.patrol.dto.DetailListDTO;
import com.gk.panda.pojo.patrol.entity.PatrolEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/edmp/largeScreen")
@Api(tags = "大屏显示接口")
public class LargeScreenController {

    @Autowired
    private DeviceManagerService deviceManagerService;

    @Autowired
    private OrgService orgService;

    @Autowired
    private LargeScreenService largeScreenService;

    @Autowired
    private DictionaryService dictionaryService;

    @Autowired
    private EquipmentPointService equipmentPointService;

    @Autowired
    private BiologyPointService biologyPointService;

//-----------------------生态管理------------------------------------

    @ApiOperation("生态管理-大屏获取生态设备信息")
    @GetMapping("/getEcologicalEquipment")
    public Result<EcologicalEqVo> getEcologicalEquipment() {
        return Result.ok(largeScreenService.getEcologicalEquipment());
    }

//-----------------------设备管理------------------------------------

    @ApiOperation("设备管理-大屏根据机构ID获取摄像机信息")
    @GetMapping("/getVidicon")
    public Result<VidiconVo> getVidiconByOrgId(Integer orgId) {
        return Result.ok(deviceManagerService.getVidiconByOrgId(orgId));
    }

    @ApiOperation("设备管理-大屏获取红外相机信息")
    @GetMapping("/getInfraredCamera")
    public Result<List<InfraredCameraVo>> getInfraredCamera() {
        return Result.ok(deviceManagerService.getInfraredCamera());
    }

    @ApiOperation("设备管理-大屏根据设备编号获取抓拍")
    @GetMapping("/getEventByDeviceSn")
    public Result<Page<RealtimeShootListVo>> getEventByDeviceSn(String deviceSn, Integer pageSize, Integer pageNumber) {
        return Result.ok(largeScreenService.getEventByDeviceSn(deviceSn,pageSize,pageNumber));
    }

    @ApiOperation("设备管理-大屏根据设备编号获取设备点位详情")
    @GetMapping("/getEquipmentPointBySn")
    public Result<EquipmentPointVo> getEquipmentPointBySn(String deviceSn) {
        return Result.ok(largeScreenService.getEquipmentPointBySn(deviceSn));
    }

    @ApiOperation("设备管理-查看设备点位列表")
    @PostMapping("/getEPList")
    public Result<List<EquipmentPointVo>> getEPList(@Validated @RequestBody EPListDto dto) {
        return Result.ok(equipmentPointService.getEPListForLS(dto));
    }

//-----------------------基层站点------------------------------------

    @ApiOperation(value = "基层站点-根据机构ID查询自己及下属机构")
    @GetMapping("/getPuisneOrg")
    public Result<List<Org>> getPuisneOrg(Integer orgId) {
        if (orgId == null) orgId = OrgEnum.CHENGDU.getOrgId();
        List<Integer> orgIds = orgService.getPuisneOrgIds(orgId);
        QueryWrapper<Org> wrapper = new QueryWrapper<>();
        wrapper.in("id", orgIds);
        return Result.ok(orgService.list(wrapper));
    }

    @ApiOperation(value = "基层站点-大屏根据机构id获取抓拍和巡护事件")
    @GetMapping("/getEventByOrgId")
    public Result<List<RealtimeShoot>> getEventByOrgId(Integer orgId,Integer pageSize,Integer includePatrol) {
        return Result.ok(largeScreenService.getEventByOrgId(orgId,pageSize,includePatrol));
    }

    @ApiOperation("基层站点-大屏获取四个区域人员信息")
    @GetMapping("/getPersonInfo")
    public Result<List<PersonVo>> getPersonInfo() {
        return Result.ok(orgService.getPersonInfo());
    }

//--------------------------------巡护管理----------------------------------
    @ApiOperation("巡护管理-大屏获取手持终端个数")
    @GetMapping("/getDeviceHandheldTerminalCount")
    public Result<Long> getDeviceHandheldTerminalCount() {
        return Result.ok(largeScreenService.getDeviceHandheldTerminalCount());
    }

    @ApiOperation("巡护管理-大屏获取四个区域巡护统计信息")
    @PostMapping("/getPatrolInfo")
    public Result<List<AreaPatrolInfo>> getPatrolInfo(@RequestBody PatrolInfoDto dto) {
        return Result.ok(largeScreenService.getPatrolInfo(dto));
    }

    @ApiOperation("巡护管理-大屏通过机构和巡护方式获取巡护记录")
    @PostMapping("/getPatrolList")
    public Result<List<PatrolEntity>> getPatrolList(@RequestBody PatrolListDto dto) {
        return Result.ok(largeScreenService.getPatrolList(dto));
    }

    @ApiOperation("巡护管理-大屏根据巡护事件编号获取对应巡护信息")
    @GetMapping("/getPatrolInfoByReportNum")
    public Result<DetailListDTO> getPatrolInfoByReportNum(String reportNum) {
        return Result.ok(largeScreenService.getPatrolInfoByReportNum(reportNum));
    }

//--------------------------------首页----------------------------------
    @ApiOperation("首页-大屏获取实时直播视频地址列表")
    @GetMapping("/getLiveVideo")
    public Result<List<String>> getLiveVideo() {
        return Result.ok(largeScreenService.getLiveVideo());
    }

    @ApiOperation("首页-登录页面背景")
    @GetMapping("/getLoginBack")
    public Result<String> getLoginBack() {
        return Result.ok(dictionaryService.getValue("loginBack"));
    }

//-----------------------------电子围栏----------------------------------
    @ApiOperation("电子围栏-大屏获取人次统计历史数据")
    @GetMapping("/getPersonCountHistoryData")
    public Result<List<PersonCountHistoryDataVo>> getPersonCountHistoryData(String startTime,String endTime) {
        return Result.ok(largeScreenService.getPersonCountHistoryData(startTime,endTime));
    }

    @ApiOperation("电子围栏-大屏导出区域人数统计历史数据")
    @GetMapping("/exportAreaUserCount")
    public void exportAreaUserCount(String startTime,String endTime,HttpServletResponse response) {
        largeScreenService.exportAreaUserCount(startTime,endTime,response);
    }

//-----------------------------巡护APP----------------------------------
    @ApiOperation("巡护APP-大屏获取下载巡护APP二维码")
    @GetMapping("/downloadPatrolAPP")
    public void downloadPatrolAPP(HttpServletResponse response) throws Exception {
        String appUrl = dictionaryService.getValue("appUrl");
        QRCodeUtil.encode(appUrl,response);
    }

    @ApiOperation("巡护APP-大屏获取下载巡护APP地址")
    @GetMapping("/downloadPatrolAPPUrl")
    public Result<String> downloadPatrolAPPUrl() throws Exception {
        return Result.ok(dictionaryService.getValue("appUrl"));
    }

//--------------------------------自然资源----------------------------------

    @ApiOperation("自然资源-大屏获取动植物点位列表")
    @PostMapping("/getBioPointList")
    public Result<List<BiologyPoint>> getBiologyPointList(@RequestBody BiologyPointSearchDto dto) {
        return Result.ok(biologyPointService.getBioPointListForLS(dto));
    }
}

